#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int n,m,mx;
veg G[N];
int rt[N];
int pw[N << 1];

namespace seg {
	const int L = 1e7 + 10;
	int val[L];
	int ch[L][2],ndn;
	int insert(int y,int &x,int k,int l = 0,int r = mx) {
		val[x = ++ndn] = val[y]; ch[x][0] = ch[y][0]; ch[x][1] = ch[y][1];
		if(l == r) return val[x] ^= 1,val[y]; int mid = l + r >> 1,res;
		if(k > mid) res = insert(ch[y][1],ch[x][1],k,mid + 1,r);
		else {
			res = insert(ch[y][0],ch[x][0],k,l,mid);
			if(res) res = insert(ch[y][1],ch[x][1],mid + 1,mid + 1,r);
		}
		val[x] = (val[ch[x][0]] + 1ll * val[ch[x][1]] * pw[mid - l + 1]) % mod; return res;
	}
	bool cmp(int x,int y,int l = 0,int r = mx) {
		if(l == r) return val[x] < val[y]; int mid = l + r >> 1;
		if(val[ch[x][1]] == val[ch[y][1]]) return cmp(ch[x][0],ch[y][0],l,mid);
		else return cmp(ch[x][1],ch[y][1],mid + 1,r);
	}
}

struct node { int x,rt; };
inline bool operator < (node a,node b) { return seg :: cmp(b.rt,a.rt); }
priority_queue < node > q;

int S,T,pre[N];
bool vis[N];
vec pot;

void calc(int x) { if(x == S) return; calc(pre[x]); pot.pb(x); }

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in,m = in; for(int i = 1,u,v,w;i <= m;i++) u = in,v = in,w = in,mx = max(mx,w),G[u].pb({v,w}),G[v].pb({u,w});
	mx += 35; for(int i = (pw[0] = 1);i <= mx;i++) pw[i] = pw[i - 1] * 2ll % mod; S = in; T = in; seg :: insert(rt[S],rt[S],0); q.push((node) { S,rt[S] });
	while(!q.empty()) {
		int x = q.top().x; q.pop(); if(vis[x]) continue; vis[x] = true;
		if(x == T) {
			printf("%d\n",(seg :: val[rt[x]] - 1 + mod) % mod);
			calc(x); printf("%d\n",pot.size() + 1); printf("%d",S); for(auto d : pot) printf(" %d",d); return 0;
		}
		for(auto d : G[x]) {
			int y = d.fi,w = d.se,nrt; seg :: insert(rt[x],nrt,w); 
			if(rt[y] == 0 || seg :: cmp(nrt,rt[y])) rt[y] = nrt,q.push((node) { y,nrt }),pre[y] = x;
		}
	} puts("-1"); return 0;
}
